package core

import (
	"gitee.com/siruihuyu/appapi/controllers"
	gameToken "gitee.com/siruihuyu/appapi/game/core/token"
	"gitee.com/siruihuyu/appapi/responsecode"
)

type GameAuthorizationController struct {
	controllers.BaseController
	token *gameToken.Token
}

func (g *GameAuthorizationController) Prepare() {
	tokenId := g.GetString("token")
	token, err := gameToken.GetGameToken(tokenId)

	if err == nil {
		if token == nil {
			g.Respond(responsecode.Unauthorized)
			g.StopRun()
		}
		g.token = token
	} else {
		g.RespondSystemError(err)
		g.StopRun()
	}
}

func (g *GameAuthorizationController) GetRoleID() int64 {
	return g.token.RoleID
}

func (g *GameAuthorizationController) GetTokenID() string {
	return g.token.TokenID
}

func (g *GameAuthorizationController) GetSessionKey() string {
	return g.token.SessionKey
}

func (g *GameAuthorizationController) GetOpenId() string {
	return g.token.OpenID
}

func (g *GameAuthorizationController) GetUserID() int64 {
	return g.token.UserID
}

func (g *GameAuthorizationController) GetUnionID() string  {
	return g.token.UnionID
}